<template>
  <div class="login">
<van-nav-bar title=""/>

	<van-row type="flex" justify="center" class="img">
		<van-col span="1">&nbsp;</van-col>
		<van-col span="22"><img src="../assets/img/login-logo.png" /></van-col>
		<van-col span="1">&nbsp;</van-col>
	</van-row>
  


  
<van-form @submit="onSubmit" 
    label-align ='cneter'

>
  <van-field
    colon
    v-model="myUserLogin.uname"
    name="用户名"
    label="用户名"
    placeholder="用户名"
    :rules="[{ required: true, message: '请填写用户名' }]"
    
  />
  <van-field
    colon
    v-model="myUserLogin.pwd"
    type="password"
    name="密码"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button size="large"  type="info" native-type="submit">登录</van-button>
  </div>
</van-form>


  </div>
</template>

<script>
import {postUserLogin} from '@/api/api'
export default {
  name: 'login',
  components: {
    
  },
  data(){
    return{
      myUserLogin:{},
      
    }
  },
  methods:{
    onSubmit(){
      let formData = new FormData();
          formData.append('uname', this.myUserLogin.uname);
          formData.append('pwd', this.myUserLogin.pwd);
          postUserLogin(formData,'newshoplogin').then(res=>{
            if (res.data.state === 1) {
              const shopId = parseInt(res.data.msg)
              sessionStorage.setItem('shopId', shopId)
              sessionStorage.setItem('shopName', res.data.shopname)
              let dateTime = parseInt(res.data.endDate+ "000")
              sessionStorage.setItem('endDate', new Date(dateTime).toLocaleDateString())
              this.$router.push('/Home')
              // 密码错误
            } else  if (res.data.state === 401) {
              this.$toast(res.data.msg);
            } else  if (res.data.state === 400) {
              this.$toast(res.data.msg);
            }
})
    }
  }
}
</script>

<style  scoped>


.login{
   text-align: center;


   
 }
  .login .van-col--22{
   margin: 20% 0;
   }
 .login .jumpBtn {
   margin-top: 10%;
 }
 .van-form{
  margin: 0 auto;
   width: 80%;
 }
 
 .van-hairline--bottom::after {
    border:0
    }
 






</style>